package com.zsxb.crm.mapper;

import com.zsxb.crm.annotation.AutoFill;
import com.zsxb.crm.annotation.Log;
import com.zsxb.crm.dto.DictPageDTO;
import com.zsxb.crm.enumeration.OperationType;
import com.zsxb.crm.pojo.Dict;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DictMapper {


    /**
     * 数据字典分页
     */
    List<Dict> pageQuery(DictPageDTO dictPageDTO);

    /**
     * 查询字典详情
     */
    List<Dict> query(Dict dict);

    /**
     *  字典类型新增
     */

    @AutoFill(OperationType.INSERT)
    @Insert("insert into sys_dict (create_by,create_time,update_by," +
            "update_time,dict_name,dict_type,remark,status)" +
            "values" +
            "(#{createBy},#{createTime},#{updateBy}," +
            "#{updateTime},#{dictName},#{dictType},#{remark},#{status})")
    void insert(Dict dict);

    /**
     * 字典类型删除
     */

    void delete(String[] dictId);

    /**
     * 字典类型修改回显
     */
    @Select("select * from sys_dict where dict_id = #{dictId}")
    Dict queryByDictId(Long dictId);

    /**
     *  字典类型修改
     */

    @AutoFill(OperationType.UPDATE)
    void update(Dict dict);

    /**
     * 根据name查询字典详情
     */
    @Select("select * from sys_dict where dict_name = #{dictName} and dict_id = #{dictId}")
    Dict queryByDictName(String dictName);

    /**
     * 根据type查询字典详情
     */
    @Select("select * from sys_dict where dict_type = #{dictType} and dict_id = #{dictId}")
    Dict queryByDictType(String dictType);

    @Select("select * from sys_dict where dict_type=#{dictType}")
    Dict findByDictType(String dictType);

    @Select("select count(*) from sys_dict")
    Long countTotal();

    @Select("select * from sys_dict")
    List<Dict> findAll();

    @Select("select * from sys_dict where dict_id=#{dictId}")
    Dict findById(Integer dictId);

    List<Dict> findByIds(String[] split);
}
